﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using Morro.VPN.Core;
using Morro.VPN.Desktop.DataDisplay;

namespace Morro.VPN.Desktop
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool _loaded = false;
        public MainWindow()
        {
            InitializeComponent();

            //AliveECGData data = AliveECGService.LoadDataFromFile(@"D:\Stella\AliveECG\AT000003.csv");
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            //scattegram.ShowData(data.ToArray());
            //mygraph.ShowData(data.ToArray());

            //scattegramm
            _loaded = true;

            //  showScattegram_Click(null,null);
        }




        private void fileOpen_Click(object sender, RoutedEventArgs e)
        {
            try
            {


                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "csv files (*.csv)|*.csv";
                //open.FileName = @"C:\Users\Dmitriy\Documents\My Dropbox\AT000003.csv";
                if (open.ShowDialog() == true)
                {
                    AliveECGData data = AliveECGService.LoadDataFromFile(open.FileName);

                    scattegramm.ShowData(data.RR);

                    gistagramm.ShowData(data.RR);

                    ritmogramm.ShowData(data.RR, data.Time);

                    gistagrammStandart.ShowData(data.RR);

                    scattegramm.AutoScale();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void menuExit_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }

        #region Comment

        private void updateParameters(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (!_loaded)
                return;

            //scattegramm.SetParameters(intervalX.Value, intervalY.Value);
        }

        private void buttonAutoInterval_Click(object sender, RoutedEventArgs e)
        {
            //double x1 = scattegramm.ActualWidth/10.0;
            //double y1 = scattegramm.ActualHeight/12.0;

            //double intervalX1 = scattegramm.ActualWidth / x1;
            //double intervalY1 = scattegramm.ActualHeight/ y1;

            scattegramm.SetParameters(10, 10);
        }

        private void scale_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (!_loaded)
                return;
            //scaleValue.Text = e.NewValue.ToString();
        }

        private void nullPointX_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            //if (!_loaded)
            //    return;
            //scattegramm.SetNullPoint(new Point(nullPointX.Value, nullPointY.Value));
        }

        private void margin_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (!_loaded)
                return;

            //scattegramm.SetMargin((int)margin.Value);
            //marginValue.Text = margin.Value.ToString();
        }

        private void checkShowBorder_Click(object sender, RoutedEventArgs e)
        {
            // scattegramm.ShowBorder = checkShowBorder.IsChecked.Value;
        }

        private void minX_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (!_loaded)
                return;

            //scattegramm.ApplyLegend(minX.Value,maxX.Value);
        }

        private void buttonAutoScale_Click(object sender, RoutedEventArgs e)
        {
            if (!_loaded)
                return;

            scattegramm.AutoScale();

        }

        private void ellipseSize_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (!_loaded)
                return;

            // scattegramm.SetEllipseSize((int)ellipseSize.Value);
        }

        #endregion


    }
}
